from google.appengine.ext import db
from google.appengine.ext.db import Key
from google.appengine.api.datastore import Get, Put
import logging
class Vehicle(db.Model):
	dbProp_str_name = db.StringProperty()
	dbProp_lst_factionKills = db.ListProperty(int)
	dbProp_int_totalKills = db.IntegerProperty()
	
	

	
class ManageVehicles():
	dict_dbPropIndexes = {"name":"dbProp_str_name",
		                  "factionKills":"dbProp_lst_factionKills",
		                  "totalKills":"dbProp_int_totalKills",
	                      
		                  }


	def BasicInit(self,int_numberToCreate):
		for i in range(0,int_numberToCreate):
			vehicle = Vehicle(dbProp_str_name)
			vehicle.put()

	def InitVehicles(self,lst_dict_intVals):
		db_id = "_dbProp_str_name"
		for dictItem in lst_dict_intVals:
			vehicle = Vehicle()
			for k, v in dictItem.iteritems():
						setattr(vehicle, k, v)
										
			
			vehicle.put()
		


	def UpdateVehicles(self, lst_dict_updVals):
		x = 5
		query = db.GqlQuery("Select * FROM Vehicle")
		results = query.fetch(limit = None)
		for iLOUV in lst_dict_updVals:
			for iRes in results:
				if iRes.dbProp_str_name == iLOUV["dbProp_str_name"]:
					for k, v in iLOUV.iteritems():
						setattr(iRes, k, v)
					iRes.put()					
					break


	def CheckHasEntities(self):
		vehicles= Vehicle.all()
		return vehicles.count(1) 

	def ReturnNumEntriesRegions(self):
		vehicles = Vehicle.all()
		return vehicles.count() 
	
	def ReturnAll(self,str_propOrderBy):
		query = db.GqlQuery("Select * FROM Vehicle ORDER BY "+ str_propOrderBy +" DESC")
		return query.fetch(limit = None)
		
		
		
